package fr.umlv.m2.jee.spij.persistence.education;

import fr.umlv.m2.jee.spij.persistence.actor.StudentProject;
import fr.umlv.m2.jee.spij.persistence.actor.TeacherProject;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity Project who contain information about project.
 *
 * @author Lounes Akroune
 * @author Aurelien Scelles
 */
@Entity
@Table(name = "PRO_PROJECT")
public class Project extends Exam {

    /**
     * Primary key.
     */
    @Id
    @Column(name = "PRO_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     * Contain of Project.
     */
    @Lob
    @Column(name = "PRO_CONTAIN", nullable = false)
    private String contain;

    /**
     * Link of Project in PDF
     */
    @Column(name = "PRO_LINK_SUPPORT")
    private String linkSupport;

    /**
     * Closing date for submission.
     *
     * @see org.joda.time.contrib.hibernate.PersistentDateTime
     */
    @Column(name = "PRO_DEADLINE")
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime deadLine;

    /**
     * Date of Project's presentation.
     *
     * @see org.joda.time.contrib.hibernate.PersistentDateTime
     */
    @Column(name = "PRO_PRESENTATION")
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime presentation;

    /**
     * Id of linked unit.
     */
    @Column(name = "PRO_UNI_ID")
    private Long unit;

    /**
     * List of students
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "SPR_PROJECT_ID", referencedColumnName = "PRO_ID")
    private List<StudentProject> students = new ArrayList<StudentProject>();

    /**
     * List of teachers
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "TPR_PROJECT_ID", referencedColumnName = "PRO_ID")
    private List<TeacherProject> teachers = new ArrayList<TeacherProject>();

    /**
     * Setter of contain.
     *
     * @param contain
     */
    public void setContain(String contain) {
        this.contain = contain;
    }

    /**
     * Getter of contain.
     *
     * @return contain
     */
    public String getContain() {
        return contain;
    }

    /**
     * Setter of linkSupport.
     *
     * @param linkSupport
     */
    public void setLinkSupport(String linkSupport) {
        this.linkSupport = linkSupport;
    }

    /**
     * Getter of linkSupport.
     *
     * @return link of Project in PDF
     */
    public String getLinkSupport() {
        return linkSupport;
    }

    /**
     * Setter of deadLine.
     *
     * @param deadLine
     */
    public void setDeadLine(DateTime deadLine) {
        this.deadLine = deadLine;
    }

    /**
     * Getter of deadLine.
     *
     * @return closing date.
     */
    public DateTime getDeadLine() {
        return deadLine;
    }

    /**
     * Getter of presentation.
     *
     * @param presentation
     */
    public void setPresentation(DateTime presentation) {
        this.presentation = presentation;
    }

    /**
     * Getter of presentation.
     *
     * @return date of presentation.
     */
    public DateTime getPresentation() {
        return presentation;
    }

    /**
     * Setter of Id.
     *
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Getter of Id.
     *
     * @return primary key
     */
    public long getId() {
        return id;
    }

    /**
     * Setter of unit.
     *
     * @param unit
     */
    public void setUnit(Long unit) {
        this.unit = unit;
    }

    /**
     * Getter of unit.
     *
     * @return id of linked unit
     */
    public Long getUnit() {
        return unit;
    }


    public void setStudents(List<StudentProject> students) {
        this.students = students;
    }

    public List<StudentProject> getStudents() {
        return students;
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addStudent(StudentProject arg0) {
        return students.add(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public StudentProject getStudent(int arg0) {
        return students.get(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeStudent(Object arg0) {
        return students.remove(arg0);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfStudents() {
        return students.size();
    }

    public void setTeachers(List<TeacherProject> teachers) {
        this.teachers = teachers;
    }

    public List<TeacherProject> getTeachers() {
        return teachers;
    }

    /**
     * @param e
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addTeacher(TeacherProject e) {
        return teachers.add(e);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public TeacherProject getTeacher(int index) {
        return teachers.get(index);
    }

    /**
     * @param o
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeTeacher(Object o) {
        return teachers.remove(o);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfTeachers() {
        return teachers.size();
    }

}
